package com.qf.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsRegionMapper;
import com.qf.pojo.DtsRegion;
import com.qf.service.DtsRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.service.impl
 * @Description:
 * @Date 2022/10/18 16:52
 */
@Service
public class DtsRegionServiceImpl implements DtsRegionService {

    @Autowired
    DtsRegionMapper regionMapper;
    @Override
    public Map<String, Object> selectByPage(Integer page, Integer limit, String name, Integer code) {
        IPage<DtsRegion> iPage = new Page<>(page,limit);

        LambdaQueryWrapper<DtsRegion> wrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(name)){
            wrapper.like(DtsRegion::getName,name);
        }
        if (code!=null){
            wrapper.like(DtsRegion::getCode,code);
        }
        iPage = regionMapper.selectPage(iPage,wrapper);

        Map<String, Object> data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return data;
    }
}
